<template>
  <div class="playlist-page">
    <div class="category-nav">
      <div class="category-item" 
           v-for="category in categories" 
           :key="category.id"
           :class="{ active: currentCategory === category.id }"
           @click="currentCategory = category.id">
        {{ category.name }}
      </div>
    </div>

    <div class="playlist-container">
      <div class="playlist-card" 
           v-for="playlist in playlists" 
           :key="playlist.id"
           @mousemove="handleMouseMove($event, playlist.id)"
           @mouseleave="handleMouseLeave(playlist.id)"
           :style="getCardStyle(playlist.id)">
        <div class="card-content-3d">
          <div class="playlist-cover">
            <img :src="playlist.cover" :alt="playlist.name">
            <div class="play-hover">
              <div class="play-btn">
                <i class="iconfont icon-play1"></i>
              </div>
            </div>
            <div class="playlist-info">
              <span class="play-count">
                <i class="iconfont icon-play1"></i>
                {{ formatCount(playlist.playCount) }}
              </span>
            </div>
            <!-- 添加光影效果 -->
            <div class="light-effect" :style="getLightStyle(playlist.id)"></div>
          </div>
          <div class="playlist-content">
            <h3 class="playlist-name">{{ playlist.name }}</h3>
            <p class="playlist-creator">
              <i class="iconfont icon-user"></i>
              {{ playlist.creator }}
            </p>
            <!-- 添加标签 -->
            <div class="playlist-tags">
              <span class="tag" v-for="tag in playlist.tags" :key="tag">{{ tag }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Playlist',
  data() {
    return {
      currentCategory: 'all',
      categories: [
        { id: 'all', name: '全部' },
        { id: 'popular', name: '流行' },
        { id: 'rock', name: '摇滚' },
        { id: 'jazz', name: '爵士' },
        { id: 'classical', name: '古典' },
        { id: 'electronic', name: '电子' }
      ],
      playlists: [
        {
          id: 1,
          name: '2023年度最热歌单',
          cover: 'https://picsum.photos/300/300?random=1',
          playCount: 1234567,
          creator: '音乐达人',
          tags: ['流行', '热门', '2023']
        },
        {
          id: 2,
          name: '治愈系音乐精选',
          cover: 'https://picsum.photos/300/300?random=2',
          playCount: 890123,
          creator: '心灵治愈师',
          tags: ['治愈', '轻音乐', '放松']
        },
        {
          id: 3,
          name: '经典流行回顾',
          cover: 'https://picsum.photos/300/300?random=3',
          playCount: 567890,
          creator: '怀旧音乐馆',
          tags: ['经典', '流行', '怀旧']
        }
      ],
      cardStates: {}
    }
  },
  methods: {
    formatCount(count) {
      if (count >= 10000) {
        return (count / 10000).toFixed(1) + '万'
      }
      return count
    },
    handleMouseMove(event, id) {
      const card = event.currentTarget;
      const rect = card.getBoundingClientRect();
      const x = event.clientX - rect.left;
      const y = event.clientY - rect.top;
      
      // 计算旋转角度
      const centerX = rect.width / 2;
      const centerY = rect.height / 2;
      const rotateX = (y - centerY) / 10;
      const rotateY = (centerX - x) / 10;
      
      // 计算光影效果位置
      const lightX = ((x / rect.width) * 100);
      const lightY = ((y / rect.height) * 100);

      this.$set(this.cardStates, id, {
        rotateX,
        rotateY,
        lightX,
        lightY
      });
    },
    handleMouseLeave(id) {
      this.$set(this.cardStates, id, {
        rotateX: 0,
        rotateY: 0,
        lightX: 50,
        lightY: 50
      });
    },
    getCardStyle(id) {
      const state = this.cardStates[id] || { rotateX: 0, rotateY: 0 };
      return {
        transform: `perspective(1000px) rotateX(${-state.rotateX}deg) rotateY(${-state.rotateY}deg)`,
        transition: this.cardStates[id] ? 'none' : 'all 0.5s ease'
      }
    },
    getLightStyle(id) {
      const state = this.cardStates[id] || { lightX: 50, lightY: 50 };
      return {
        background: `radial-gradient(circle at ${state.lightX}% ${state.lightY}%, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 60%)`
      }
    }
  }
}
</script>

<style scoped>
.playlist-page {
  padding: 20px;
  perspective: 1000px;
}

.category-nav {
  display: flex;
  gap: 15px;
  margin-bottom: 30px;
  padding: 15px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
  overflow-x: auto;
}

.category-item {
  padding: 8px 20px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  background: #f5f5f5;
}

.category-item:hover {
  background: #ffd6d6;
  color: #ff6b6b;
  transform: translateY(-2px);
}

.category-item.active {
  background: linear-gradient(45deg, #ff6b6b, #ffd93d);
  color: white;
  box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

.playlist-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 30px;
  padding: 20px;
}

.playlist-card {
  position: relative;
  transform-style: preserve-3d;
  transform: perspective(1000px);
  cursor: pointer;
}

.card-content-3d {
  position: relative;
  width: 100%;
  height: 100%;
  background: white;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 15px 35px rgba(0,0,0,0.2);
  transition: transform 0.1s ease;
}

.playlist-cover {
  position: relative;
  padding-top: 100%;
  overflow: hidden;
}

.playlist-cover img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.playlist-card:hover .playlist-cover img {
  transform: scale(1.1);
}

.play-hover {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.3s ease;
}

.play-btn {
  width: 60px;
  height: 60px;
  background: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(20px);
  transition: all 0.3s ease;
}

.play-btn i {
  font-size: 24px;
  color: #ff6b6b;
  margin-left: 4px;
}

.playlist-card:hover .play-hover {
  opacity: 1;
}

.playlist-card:hover .play-btn {
  transform: translateY(0);
}

.playlist-info {
  position: absolute;
  top: 10px;
  right: 10px;
  color: white;
  font-size: 12px;
  z-index: 2;
}

.play-count {
  background: rgba(0,0,0,0.5);
  padding: 4px 12px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  gap: 4px;
  backdrop-filter: blur(4px);
}

.playlist-content {
  padding: 20px;
  background: white;
  position: relative;
  z-index: 1;
}

.playlist-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.playlist-creator {
  font-size: 14px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.playlist-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  padding: 4px 12px;
  background: #f8f9fa;
  border-radius: 12px;
  font-size: 12px;
  color: #666;
  transition: all 0.3s ease;
}

.tag:hover {
  background: #ff6b6b;
  color: white;
  transform: translateY(-2px);
}

/* 光影效果 */
.light-effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: overlay;
}

/* 添加卡片阴影动画 */
@keyframes float {
  0%, 100% {
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
  }
  50% {
    box-shadow: 0 25px 45px rgba(0,0,0,0.1);
  }
}

/* 响应式调整 */
@media (max-width: 768px) {
  .playlist-container {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
    padding: 10px;
  }
  
  .category-nav {
    padding: 10px;
  }
  
  .category-item {
    padding: 6px 15px;
    font-size: 14px;
  }

  .play-btn {
    width: 40px;
    height: 40px;
  }

  .play-btn i {
    font-size: 18px;
  }
}
</style> 